'''
Cookie
'''
from typing import Union, List, Annotated

from fastapi import APIRouter, Path, Body, Cookie, Header
from pydantic import BaseModel

router = APIRouter()


# 请求头
@router.get("/header/items_2/", tags=["header"])
async def read_items(user_agent: Union[str, None] = Header(default=None),
                     strange_header: Union[str, None] = Header(default=None, convert_underscores=False)):
    return {"User-Agent": user_agent, "strange_header": strange_header}


@router.get("/header/items_3/")
async def read_items(x_token: Union[List[str], None] = Header(default=None)):
    return {"X-Token values": x_token}


# cookie
@router.get("/header/items_1/", tags=["cookie"])
async def read_items(ads_id: Union[str, None] = Cookie(default=None)):
    return {"ads_id": ads_id}


@router.post("/cookie/items_2/", tags=["cookie"])
async def read_items(ads_id: Annotated[Union[str, None], Cookie()] = None):
    print(f'======> cookie ： {ads_id}')
    return {"ads_id": ads_id}


class Cookies(BaseModel):
    session_id: str
    fatebook_tracker: Union[str, None] = None
    googall_tracker: Union[str, None] = None


@router.get("/cookie/items_3/", tags=["cookie"])
async def read_items_2(cookies: Annotated[Cookies, Cookie()]):
    return cookies.fatebook_tracker
